package com.wyj.demo.common.websocket

import com.custom.util.RxBus
import com.wyj.demo.common.event.SendMessage
import org.java_websocket.client.WebSocketClient
import org.java_websocket.handshake.ServerHandshake
import java.lang.Exception
import java.net.URI
import org.java_websocket.drafts.Draft_6455


class WsClient(serverUri: URI?) : WebSocketClient(serverUri, Draft_6455()) {

    override fun onOpen(handshakedata: ServerHandshake?) {
        RxBus.send(SendMessage("WsClient onOpen"))
    }

    override fun onClose(code: Int, reason: String?, remote: Boolean) {
        RxBus.send(SendMessage("WsClient onClose"))
    }

    override fun onMessage(message: String?) {
        RxBus.send(SendMessage("WsClient onMessage"))
    }

    override fun onError(ex: Exception?) {
        RxBus.send(SendMessage("WsClient onError"))
    }
}